﻿@model chihuopig.DTO.RoleModelEdit
@{ 
    string[] Checkdian = string.IsNullOrWhiteSpace(Model.roleDto.authorizationId)? new string[] { "0" } : Model.roleDto.authorizationId.Split(',');
    }
    @section Header{

    }
<div class="x-body">
    <form action="" method="post" class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>角色名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" required="" lay-verify="required"
                       autocomplete="off" value="@Model.roleDto.RoleName" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">
                拥有权限
            </label>
            <table class="layui-table layui-input-block">
                <tbody>
                    @foreach (var item in Model.rolm)
                    {

                        <tr>
                            <td>
                                @item.MenuName
                            </td>
                            <td>
                                <div class="layui-input-block">
                                    @if (!string.IsNullOrWhiteSpace(item.JurisAny))
                                    {
                                        var ModeList = item.JurisAny.Split(',');
                                        
                                        foreach (var vl in ModeList)
                                        {
                                            string[] chen = vl.Split('-');
                                            <input name="JurisAny" lay-skin="primary" @(Checkdian.Contains(chen[1])?"checked":"") title="@chen[0]" type="checkbox" id="@chen[1]" value="2">
                                        }

                                    }

                                </div>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
        <div class="layui-form-item">
            <input type="button" onclick="btnsvae()" class="layui-btn" value="修改" />
        </div>
    </form>
</div>
@section footer{
    <script>
    function btnsvae() {
        var listar = [];
        $("input[name='JurisAny']:checked").each(function (index, item) {
            listar.push($(item).attr("id"));
            //alert($(item).attr("id"));
        });

        if ($("input[name='name']").val() == "") {

            layer.msg('角色名不能为空', { icon: 2 });
            return;
        }

        if ($("input[name='name']").val().length > 20) {
            layer.msg('角色名的长度都大于20', { icon: 2 });
            return;
        }
        if (listar.length <= 0) {
            layer.msg('请选择权限', { icon: 2 });
            return;
        }
        $.post("/admin/adminrole/roleEdit",
            {
                "RoleName": $("input[name='name']").val(),
                "jurisd": listar,
                "RoleId": @ViewBag.RoleId
            }, function (data) {

                if (!data.succeed) {

                    layer.msg(data.msg);
                }
                else
                {
                    layer.msg(data.msg);
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                }
            })


    }

    </script>
}